﻿using System;

using Mvc.XForms.Utilities;

namespace Mvc.XForms {
	/// <summary>
	/// See http://www.w3.org/TR/xforms11/#rpm-events
	/// </summary>
	public enum XFormEvent {
		// Not the full list, we'll add to this as required
		Insert,
		Delete,
		ValueChanged,
		Valid,
		Invalid,
		DOMActivate,
		DOMFocusIn,
		DOMFocusOut,
		Rebuild,

		// Not XForms events - use incremental="true"
		OnKeyUp,
		OnKeyDown
	}

	public static class XFormsEventExtensions {
		public static string ToScriptName(this XFormEvent eventType) {
			switch (eventType) {
				case XFormEvent.DOMActivate:
					return "click";
				case XFormEvent.DOMFocusIn:
					return "focus";
				case XFormEvent.DOMFocusOut:
					return "blur";
				case XFormEvent.ValueChanged:
					return "change";
				case XFormEvent.OnKeyUp:
					return "onkeyup";
				case XFormEvent.OnKeyDown:
					return "onkeydown";
				default:
					var eventStr = "xforms-" + eventType.ToString()
						.CapitalizeSpace()
						.Replace(' ', '-')
						.ToLower();
					return eventStr;
			}
		}
	}
}